﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Linq.Expressions;
using VietPay.KooBoo.Data.Interfaces;
using VietPay.KooBoo.Data.EntityModels;
using System.Data.Objects;
using VietPay.KooBoo.Data.Infrastructure;

namespace VietPay.KooBoo.Data
{
    public class StockBalanceRepository : RepositoryBase<StockBalance>, IStockBalanceRepository
    {
        

        public StockBalanceRepository()
            : this(new DmsRepositoryContext())
        {

        }

        public StockBalanceRepository(IRepositoryContext repositoryContext)
            : base(repositoryContext)
        {
            
        }

        public IQueryable GetStockBalance(int distributorID)
        {
            var vms = new VMS2_DistributorEntities();

            var result = (from a in vms.StockBalances
                          join p in vms.Products on a.ProductID equals p.ProductID
                          join c in vms.Categories on p.CategoryID equals c.CategoryID
                          where a.DistributorID == distributorID
                          select new
                          {
                              a.BalanceID,
                              c.CategoryName,
                              p.ProductName,
                              a.Quantity
                          }).OrderBy(p => p.CategoryName);

            
            return result;

        }
    }
}
